package _base0to1;

import java.util.Optional;
import java.util.Stack;

/**
 * 682. 棒球比赛
 */
public class No682 {
    public int calPoints(String[] operations) {
        Stack<Integer> stack = new Stack<>();
        for (String operation : operations) {
            switch (operation) {
                case "+":
                    Integer temp = stack.pop();
                    int i = temp + stack.peek();
                    stack.push(temp);
                    stack.push(i);
                    break;
                case "D":
                    stack.push(stack.peek() * 2);
                    break;
                case "C":
                    stack.pop();
                    break;
                default:
                    stack.push(Integer.valueOf(operation));
                    break;
            }
        }
        int answer = 0;
        for (Integer i : stack) {
            answer += i;
        }
        return answer;
    }
}
